﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ECRMS.WinForm.BaseClass;
using System.Linq;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using ECRMS.WinForm.BaseClass;
using ECRMS.WinForm.BaseClass.Common;
using ECRMS.WinForm.Properties;
using ECRMS.WinForm.WinService;
using ECRMS.WinForm.ModuleEdits;
using System.Linq;
using ECRMS.WinForm.BaseClass.Other;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using ECRMS.WinForm.Modules.BaseChartControl;

namespace ECRMS.WinForm.Modules
{
     [ModuleInstance((int)ModuleEnum.测评结果)]
    public partial class TargetResultModule : BaseModule

    {
        public TargetResultModule()
        {
            base.core.CreateWaitDialog("初始化中...", "指标分析");
            InitializeComponent();
            InitView();
            InitData();
            InitEventHandler();
            base.core.CloseWaitDialog();

        }

        private void InitEventHandler()
        {
            //语言切换
            base.core.LangChanged += new Core.LanguageChangedHandler(this.ChangeLanguage);
        }

        private void ChangeLanguage(LangEnum lang)
        {
            //switch (core.NowLanguage)
            switch (lang)
            {
                case LangEnum.China:
                case LangEnum.中文:

                    break;
                case LangEnum.English:
                case LangEnum.英文:

                    break;
                default:
                    break;
            }
        }

        private void InitView()
        {
            base.newBarButtonVisiable = false;
            base.updateBarButtonVisiable = false;
            base.delBarButtonVisiable = false;
            base.selectBarButtonVisiable = false;
            base.saveBarButtonVisiable = false;
            base.otherBarButton2Visiable = false;
            base.otherBarButton3Visiable = false;
            base.outBarButtonVisiable = false;
            base.otherBarButton1Visiable = false;
        }

        private void InitData()
        {
            FuncResult result = core.CoreIndexResult.GetAllIndexResults(core.CoreUser.UserInfo.CorporationRefId);
            if (result.Status == 0)
            {
                XtraMessageBox.Show(this, Language_ch.ResourceManager.GetString(result.Message));
                return;
            }

            ChartDemoBarSideBySide allChart = new ChartDemoBarSideBySide()
            {
                Dock = DockStyle.Fill
            };
            allChart.InitData(core.CoreIndexResult.IndexTotalResults);
            tab1.Controls.Add(allChart);


            this.gd1.DataSource = core.CoreIndexResult.IndexGroups;
            this.gd1.RefreshDataSource();
            this.gd1.Select();
            BindFirstLevelChart();

            this.gd2.DataSource = core.CoreIndexResult.IndexGroups;
            this.gd2.RefreshDataSource();
            this.gd2.Select();
            BindSecondLevelChart();
        }

        private void BindFirstLevelChart()
        {
            Guid rowIndex = core.CoreCommon.GetGridFocusRowRefId(gd1,gridView1, "IndexGroupRefId");
            ChartDemoBarSideBySide firstLevelChart = new ChartDemoBarSideBySide()
            {
                Dock = DockStyle.Fill
            };
            firstLevelChart.InitData(core.CoreIndexResult.IndexFirstResults.Where(p=>p.IndexGroupRefId==rowIndex).ToList());
            splitContainerControl1.Panel2.Controls.Add(firstLevelChart);
        }

        private void BindSecondLevelChart()
        {
            Guid rowIndex = core.CoreCommon.GetGridFocusRowRefId(gd2, gridView2, "IndexGroupRefId");

            ChartDemoBarSideBySide secondLevelChart = new ChartDemoBarSideBySide()
            {
                Dock = DockStyle.Fill
            };
            secondLevelChart.InitData(core.CoreIndexResult.IndexSecondResults.Where(p=>p.IndexGroupRefId==rowIndex).ToList());
            splitContainerControl2.Panel2.Controls.Add(secondLevelChart);
        }

        public override void refreshBarButton_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            base.refreshBarButton_ItemClick(sender, e);
            base.core.CreateWaitDialog("初始化中...", "指标分析");
            InitData();
            base.core.CloseWaitDialog();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            BindFirstLevelChart();
        }

        private void gridView2_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            BindSecondLevelChart();
        }


    }
}
